// run: $exec < bfdiff.in

#include<stdio.h>
#include<stdlib.h>
#include<algorithm>

using std::swap;
using std::min;
using std::max;

const int INF=9999999;

inline bool cross(int l1,int r1,int l2,int r2)
{
	return !(r1<l2 || r2<l1);
}
inline bool in(int y,int l,int r)
{
	return l<=y && y<=r;
}
int n,bwx,bwy,dis;
int check(int sx,int sy,int ex,int ey,int step)
{
	int i,l,r,x;
	int dir=ex>sx?1:-1;
	for(i=1;i<=step;++i)
	{
		l=max(1,max(sy-i,ey-(dis-i)));
		r=min(n,min(sy+i,ey+(dis-i)));
		x=sx+dir*i;
		if(((x==bwx-i || x==bwx+i) && cross(l,r,bwy-i,bwy+i))
				|| (abs(bwx-x)<i && (in(bwy-i,l,r) || in(bwy+i,l,r))))
			return i;
	}
	return INF;
}

int main()
{
#ifdef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int bx,by,wx,wy;
	scanf("%d%d%d%d%d%d%d",&n,&bx,&by,&wx,&wy,&bwx,&bwy);
	if(abs(bx-wx)<abs(by-wy))
	{
		swap(bx,by);
		swap(wx,wy);
		swap(bwx,bwy);
	}
	dis=abs(bx-wx);
	int ans=min(check(bx,by,wx,wy,dis/2-1),check(wx,wy,bx,by,dis/2-1));
	if(ans!=INF)
		printf("YES\n%d\n",ans);
	else printf("NO\n%d\n",dis-1);
	return 0;
}

